const momentService = require('../service/moment.service')


class MomentController {
    async list(ctx, next) {

        const { page, size, type_id } = ctx.query;

        const result = await momentService.getMomentList(page, size, type_id);

        ctx.body = result;
    }
    async detail(ctx, next) {
        const { momentId } = ctx.params;
        console.log(momentId);

        const result = await momentService.getMomentById(momentId);

        ctx.body = result;
    }
    async create(ctx, next) {
        const moment = ctx.request.body;
        const result = await momentService.create(moment);
        console.log(result);
        if (result.length >= 1) {
            ctx.body = {
                code: 0,
                message: ''
            };
        } else {
            ctx.body = {
                code: 400,
                message: '请求错误'
            };
        }

    }
    async edit(ctx, next) {
        const moment = ctx.request.body;
        const result = await momentService.edit(moment);
        if (result.length >= 1) {
            ctx.body = {
                code: 0,
                message: ''
            };
        } else {
            ctx.body = {
                code: 400,
                message: '请求错误'
            };
        }
    }
    async remove(ctx, next) {
        // 1.获取momentId
        const { momentId } = ctx.params;

        // 2.删除内容
        const result = await momentService.remove(momentId);
        if (result.length >= 1) {
            ctx.body = {
                code: 0,
                message: ''
            };
        } else {
            ctx.body = {
                code: 400,
                message: '请求错误'
            };
        }
    }
}

module.exports = new MomentController();